<?php
/**
 * Created by PhpStorm.
 * User: Mak
 * Date: 2016/1/5
 * Time: 9:02
 */

namespace Home\Model;
use Think\Model;

class StuInfoModel extends Model{

    protected $tableName="StuInfo";

    public function getList() {
        $ret = $this->order('id asc')->select();
        return $ret;
    }

    public function getItem($name){
        $condition['name'] = $name;
        $ret = $this->where($condition)->find();
        return $ret;
    }

    // 验证登陆，返回1-正确；0；密码错； -1：用户名错。
    public function checkUser($name, $stuid){
        $name = htmlspecialchars(trim($name));
        $stuid = md5(htmlspecialchars(trim($stuid)));
        $ret = $this->getItem($name);
        if (count($ret)>0) {
            if ($ret['stuid'] === $stuid){
                return 1;   // 正确
            }else {
                return 0;  // 密码错误
            }
        }else {
            return -1;  // 账号不存在或错误。
        }
    }
}